<template>
  <div>
    <fm-generate-form
      ref="generateForm"
      :data="jsonData"
      :remote="remoteList"
      :value="formData"
    />
  </div>
</template>
<script>
import { getDeptTree } from '@/api/bpmn/bpmn'
import * as COM from '@/api/common.js'
const getUser = function() {
  return new Promise(function(reslove){
    COM.jsonsqlForSelect({
      'sys_user:data[]': {
        '@column': 'user_id,account:value,name:label',
        '@where': {
          'status@eq':'ENABLE'
        },
        '@join':[
          {
            'sys_dept@leftOutJoin':{
              '@column': 'simple_name',
              '@on': {
                'dept_id':'data/dept_id'
              }
            }
          }
        ]
      }
    }).then(res => {
      res.data.forEach(item => {
        item.label = `${item.value}-${item.label}-${item.simple_name}`
      })
      reslove(res.data)
    })
  })
}
export default {
  props:{
    jsonData:{
      type:Object,
      default:() => {}
    },
    formData:{
      type:Object,
      default:() => {}
    }
  },
  data () {
    return {
      remoteList:{
        'getDeptTree':getDeptTree,
        'getUser':getUser
      }
    }
  },
  created() {
    console.log('this.jsonData', JSON.parse(JSON.stringify(this.jsonData)))
    console.log('this.this.formData', this.formData)
  },
  methods: {
    handleSubmit () {
      console.log('dddddddddddddddddd')
      console.log(this.$refs.generateForm.getData())
      this.$refs.generateForm.getData().then(data => {
        this.$emit('getFormData',JSON.stringify(data))
      }).catch(err =>{
        console.log('err===', err)
      })
    }
  }
}
</script>
